<?php 
    

function list_mpp($start , $limit){
	list($dd1,$mm1,$yyyy1) = explode("-" , $_GET['tanggal']);
	list($dd2,$mm2,$yyyy2) = explode("-" , $_GET['tanggal2']);
	$startDate = $yyyy1.'-'.$mm1.'-'.$dd1; 
	$endDate = $yyyy2.'-'.$mm2.'-'.$dd2; 
	$header = array( 
		'Prediksi Pensiun'=>array('style'=>'border-bottom:2px solid;width:80px'),  
		'NIK'=>array('style'=>'text-align:left;border-bottom:2px solid;width:80px'),  
		
		'Nama karyawan'=>array('style'=>'text-align:left;border-bottom:2px solid;width:290px'),  
		'Jabatan'=>array('style'=>'text-align:left;border-bottom:2px solid;width:380px'),  
		'Tgl. Lahir'=>array('style'=>'border-bottom:2px solid;width:120px')   
		);
	$query = "SELECT a.karyawan_id,
		DATE_ADD(b.tanggal_lahir,INTERVAL 56 YEAR) as period,
		b.tanggal_lahir FROM `karyawan`a
		INNER JOIN biodata b ON a.biodata_id=b.biodata_id 
		WHERE a.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)
		 
		AND   ( 
		 '{$endDate}' >=  	DATE_ADD(b.tanggal_lahir, INTERVAL 56 YEAR)
			AND
		 '{$startDate}' <=  DATE_ADD(b.tanggal_lahir, INTERVAL 56 YEAR)
		)
		
		AND a.karyawan_id NOT IN (select karyawan_id FROM pemberhentian) 
		ORDER BY YEAR(period),MONTH(period) LIMIT {$start} , {$limit}";
	 
	$result = my_query($query);
	 	
	$row = array();  
	while( $ey = my_fetch_array($result) ){
		$i++;
		$karyawan = loaddata_karyawan($ey['karyawan_id']);  
		$jab = loaddata_jabatan($karyawan['jabatan_id']);
		$row[] = array( 
			'prediksi'=> date('d-m-Y',strtotime($ey['period'])) ,  	
			'nik'=>      $karyawan['nik'] ,   
			'nama'=> $karyawan['nama_gelar']   , 
			'jbt'=>  $jab['nama_jabatan']   , 
			'tmb'=>    date( "d-m-Y" , strtotime($ey['tanggal_lahir'] )) , 
		
		);
	}
	
	$datas = table_cetak_rows($row);   
	return  table_cetak_builder($header , $datas ,  4 , false );
} 
?>
<style type="text/css">
<!--

	table.page_header {width: 100%; border: none; background-color: #CDCDCD; border-bottom: solid 1mm #000; padding: 2mm }
	table.page_footer {width: 100%; border: none;  border-top: solid 1mm #000; padding: 2mm}
div.zone
{
	border: solid 2mm #66AACC;
	border-radius: 3mm;
	padding: 1mm;
	background-color: #FFEEEE;
	color: #440000;
}
div.zone_over
{
	width: 30mm;
	height: 35mm;
	overflow: hidden;
}

-->
</style>
<?php 
	list($dd1,$mm1,$yyyy1) = explode("-" , $_GET['tanggal']);
	list($dd2,$mm2,$yyyy2) = explode("-" , $_GET['tanggal2']);
	$startDate = $yyyy1.'-'.$mm1.'-'.$dd1; 
	$endDate = $yyyy2.'-'.$mm2.'-'.$dd2;
	
	$query = "SELECT a.karyawan_id,
		DATE_ADD(b.tanggal_lahir,INTERVAL 56 YEAR) as period,
		b.tanggal_lahir FROM `karyawan`a
		INNER JOIN biodata b ON a.biodata_id=b.biodata_id 
		WHERE a.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)
		 
		AND   ( 
		 '{$endDate}' >=  	DATE_ADD(b.tanggal_lahir, INTERVAL 56 YEAR)
			AND
		 '{$startDate}' <=  DATE_ADD(b.tanggal_lahir, INTERVAL 56 YEAR)
		)
		
		AND a.karyawan_id NOT IN (select karyawan_id FROM pemberhentian) 
		ORDER BY YEAR(period),MONTH(period)";
	 
	$result = my_query($query);
	$total = my_num_rows($result);
	$limit = 20;
	$total_page = ceil($total/$limit) -1; 
	for($i = 0; $i<=  $total_page  ;$i++):
	$start =  ( $i * $limit );
	
?>	 
<page style="font-size: 10pt">
	<page_footer>
		<table class="page_footer">
			<tr>
				<td style="width: 33%; text-align: left;">
					Laporan Masa Persiapan Pension :: HRIS RSKM
				</td>
				<td style="width: 34%; text-align: center">
					page [[page_cu]]/[[page_nb]]
				</td>
				<td style="width: 33%; text-align: right">
					M A P &copy; 2010 - <?php echo date('Y'); ?>
				</td>
			</tr> 
		</table>
	</page_footer>

	<div style="width: 100%; text-align:center; padding:2px; font-size: 13pt ;">Laporan Masa Persiapan Pension<br>Periode : <?php echo $_GET['tanggal'].' s/d '. $_GET['tanggal2'];?><br><br></div>
	<?php echo list_mpp($start , $limit); ?> 
</page>
<?php endfor; ?>